package lumingweihua.future.cn.lumingweihua.home.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialogEntity;
import lumingweihua.future.cn.lumingweihua.R;

/**
 * @描述 是否选择通用框
 * @Copyright Copyright (c) 2016
 * @version 1.0
 */
public class YesOrNoDialog extends Dialog implements OnClickListener {
    private YesOrNoDialogEntity dialogEntity;
    private lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialog.OnYesOrNoDialogClickListener listener;
    private TextView mSureBtn;
    private TextView mCancelBtn;
    private TextView mYesOrNoLabel;
    public YesOrNoDialog(Context context, YesOrNoDialogEntity dialogEntity,
                         lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialog.OnYesOrNoDialogClickListener listener) {
        super(context, R.style.BMF_Dialog);
        this.dialogEntity = dialogEntity;
        this.listener = listener;
        setCanceledOnTouchOutside(true);
        setContentView(R.layout.common_simple_dialog2);
        initViews();
        notifyDataSetChanged();

    }
    
    public void changeDialogMsg(String msg){
        this.dialogEntity.titleOne = msg;
        notifyDataSetChanged();
    }

    /**
     * 
     */
    private void initViews() {
        mYesOrNoLabel = (TextView) this.findViewById(R.id.tv_content);
        mSureBtn = (TextView) this.findViewById(R.id.bt_yes);
        mCancelBtn = (TextView) this.findViewById(R.id.bt_no);
        mSureBtn.setOnClickListener(this);
        mCancelBtn.setOnClickListener(this);

        mYesOrNoLabel.setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    private void notifyDataSetChanged() {
        if (!TextUtils.isEmpty(dialogEntity.btnCancelLabel)) {
            mCancelBtn.setText(dialogEntity.btnCancelLabel);
            mCancelBtn.setVisibility(View.VISIBLE);
        } else {
            mCancelBtn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(dialogEntity.btnOkLabel)) {
            mSureBtn.setText(dialogEntity.btnOkLabel);
            mSureBtn.setVisibility(View.VISIBLE);
        } else {
            mSureBtn.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(dialogEntity.titleOne)) {
            mYesOrNoLabel.setText(dialogEntity.titleOne);
            mYesOrNoLabel.setVisibility(View.VISIBLE);
        } else {
            mYesOrNoLabel.setVisibility(View.GONE);
        }
    }
    @Override
    public void onClick(View v) {

        if (v.getId()==R.id.bt_yes){
            dismiss();
            if (listener != null) {
                listener.onYesOrNoDialogClick(lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialog.YesOrNoType.BtnOk);
            }
        }else if(v.getId()==R.id.bt_no){
            dismiss();
            if (listener != null) {
                listener.onYesOrNoDialogClick(lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialog.YesOrNoType.BtnCancel);
            }
        }
    }

//    public interface OnYesOrNoDialogClickListener {
//        void onYesOrNoDialogClick(YesOrNoType yesOrNoType);
//    }
//
//    public enum YesOrNoType {
//        BtnCancel, BtnOk
//    }
}
